﻿using System.Collections.Generic;
using Hammock.Web;
using Weibo4Sharp.Model;
using Weibo4Sharp.Model.Enums;

namespace Weibo4Sharp.Service
{
    public partial class WeiboService
    {
        public virtual WeiboUser GetUserProfileFor(string screenName)
        {
            return WithHammock<WeiboUser>("users/show", FormatAsString, "?screen_name=", screenName);
        }

        public virtual WeiboUser GetUserProfileFor(long id)
        {
            return WithHammock<WeiboUser>("users/show", FormatAsString, "?id=", id);
        }

        public virtual IEnumerable<WeiboUser> SearchForUser(string q)
        {
            return WithHammock<IEnumerable<WeiboUser>>("users/search", FormatAsString, "?q=", q);
        }

        public virtual IEnumerable<WeiboUser> SearchForUser(string q, int perPage)
        {
            return WithHammock<IEnumerable<WeiboUser>>("users/search", FormatAsString, "?q=", q, "&per_page=", perPage);
        }

        public virtual IEnumerable<WeiboUser> SearchForUser(string q, int page, int perPage)
        {
            return WithHammock<IEnumerable<WeiboUser>>("users/search", FormatAsString, "?q=", q, "&page=", page, "&per_page=", perPage);
        }

        public virtual IEnumerable<WeiboUser> ListUserProfilesFor(IEnumerable<string> screenName)
        {
            return WithHammock<IEnumerable<WeiboUser>>("users/lookup", FormatAsString, "?screen_name=", screenName);
        }

        public virtual IEnumerable<WeiboUser> ListUserProfilesFor(IEnumerable<long> userId)
        {
            return WithHammock<IEnumerable<WeiboUser>>("users/lookup", FormatAsString, "?user_id=", userId);
        }

        public virtual IEnumerable<WeiboUser> ListUserProfilesFor(IEnumerable<string> screenName, IEnumerable<long> userId)
        {
            return WithHammock<IEnumerable<WeiboUser>>("users/lookup", FormatAsString, "?screen_name=", screenName, "&user_id=", userId);
        }

        public virtual byte[] GetProfileImageFor(string screenName)
        {
            return WithHammock<byte[]>("users/profile_image/{screen_name}", FormatAsString, "?screen_name=", screenName);
        }

        public virtual byte[] GetProfileImageFor(string screenName, WeiboProfileImageSize size)
        {
            return WithHammock<byte[]>("users/profile_image/{screen_name}", FormatAsString, "?screen_name=", screenName, "&size=", size);
        }

        /// <summary>
        /// List Hot Users
        /// </summary>
        /// <param name="cetegory">default|ent|hk_famous|model|cooking|sport|finance|tech|singer|writer|moderator|medium|stockplayer</param>
        /// <returns></returns>
        public IEnumerable<WeiboUser> ListHotUsers(string cetegory = "default")
        {
            return WithHammock<IEnumerable<WeiboUser>>(
                "users/hot", FormatAsString,
                "?category=", cetegory);
        }

        /// <summary>
        /// Update the remark of a friend
        /// </summary>
        /// <param name="userId">friend's userid</param>
        /// <param name="remark">new remark to upadte</param>
        /// <returns></returns>
        public WeiboUser UpdateRemark(long userId, string remark)
        {
            return WithHammock<WeiboUser>(WebMethod.Post,
                "user/friends/update_remark", FormatAsString,
                "?user_id=", userId,
                "&remark=", remark);
        }

        /// <summary>
        /// List the suggested users
        /// </summary>
        /// <param name="withReason">0|1</param>
        /// <returns></returns>
        public IEnumerable<WeiboUser> ListSuggestedUsers(int withReason = 0)
        {
            return WithHammock<IEnumerable<WeiboUser>>(
                "users/suggestions", FormatAsString,
                "?with_reason=", withReason);
        }
    }
}
